package main

import (
	"crypto/tls"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main()  {

	// http
	response, err := http.Get("http://www.baidu.com")
	CheckErr(err)

	defer func() {
		err = response.Body.Close()
		CheckErr(err)
	}()


	body, err := ioutil.ReadAll(response.Body)
	CheckErr(err)
	fmt.Println(string(body))

	// https
	tr := &http.Transport{
		TLSClientConfig:&tls.Config{InsecureSkipVerify:true},  // 跳过证书校验
	}

	client := &http.Client{Transport:tr}

	httpsRes, err := client.Get("https://studygolang.com/pkgdoc")
	CheckErr(err)
	defer func() {
		err = httpsRes.Body.Close()
		CheckErr(err)
	}()
	httpsBody, err := ioutil.ReadAll(httpsRes.Body)
	CheckErr(err)
	fmt.Println(string(httpsBody))

}

func CheckErr(err error)  {
	if err != nil {
		panic(err)
	}
}
